<template>
  <el-main>

    <el-select v-model="seachEsEntity.status" placeholder="请选择出租状态" clearable>
      <el-option
        v-for="item in statuss"
        :label="item.label"
        :value="item.value">

      </el-option>
    </el-select>

    <el-select v-model="seachEsEntity.publishStatus" placeholder="请选择发布状态" clearable>
      <el-option
        v-for="item in publishStatuss"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>

    <el-input v-model="seachEsEntity.name" placeholder="请输入楼盘关键字" clearable></el-input>

    <el-input v-model="seachEsEntity.roomName" placeholder="请输入房源关键字" clearable></el-input>

    <el-button type="primary" @click="list">查询</el-button>
    <el-button type="warning" @click="updateAllEs">es全量同步</el-button>
    <br>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        label="序号"
        width="80">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        prop="id"
        label="id">
        <template slot-scope="scope">
          <span>
            {{ scope.row.id.substring(0, 6) }}...
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="图片">
        <template slot-scope="scope">
          <img :src="scope.row.frontCover" width="100px">
        </template>
      </el-table-column>
      <el-table-column
        label="房源名称">
        <template slot-scope="scope">
          <span v-html="scope.row.roomName"></span>
        </template>
      </el-table-column>
      <el-table-column
        label="楼盘名称">
        <template slot-scope="scope">
          <span v-html="scope.row.name"></span>
        </template>
      </el-table-column>
      <el-table-column
        prop="rommCode"
        label="房源编号">
      </el-table-column>
      <el-table-column
        prop="proportion"
        label="面积">
      </el-table-column>
      <el-table-column
        prop="rental"
        label="租金">
      </el-table-column>
      <el-table-column
        label="出租状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status==0">待租中</span>
          <span v-if="scope.row.status==1">已出租</span>
          <span v-if="scope.row.status==2">装修中</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="userName"
        label="发布人">
      </el-table-column>
      <el-table-column
        label="发布状态">
        <template slot-scope="scope">
          {{ scope.row.publishStatus == 0 ? "未发布" : "已发布" }}
        </template>
      </el-table-column>
      <el-table-column
        label="是否推荐">
        <template slot-scope="scope">
          <span>{{ scope.row.recommended == 1 ? "推荐" : "不推荐" }}</span>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="seachEsEntity.pageNum"
        :page-sizes="[1, 7, 10, 20]"
        :page-size="seachEsEntity.pageSize"
        :page-count="pages"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </el-main>
</template>

<script>

import {seachEsHousingList, updateAllEs} from "@/api/housing/housinglist";

export default {
  data() {
    return {
      //列表
      tableData: [],
      //查询对象
      seachEsEntity: {
        pageNum: 1,
        pageSize: 10
      },
      //总条数
      total: undefined,
      pages: 0,
      // 出租状态
      statuss: [
        {label: "待租中", value: 0},
        {label: "已出租", value: 1},
        {label: "装修中", value: 2}
      ],
      // 发布状态
      publishStatuss: [
        {label: "未发布", value: 0},
        {label: "已发布", value: 1}
      ]
    }
  },
  methods: {
    list() {
      seachEsHousingList(this.seachEsEntity).then(res => {
        console.log(res);
        this.tableData = res.msgData.content;
        this.total = res.msgData.totalElements;
        this.pages = res.msgData.totalPages;
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.seachEsEntity.pageNum = 1;
      this.seachEsEntity.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.seachEsEntity.pageNum = val;
      this.list();
    },
    updateAllEs() {
      updateAllEs().then(res => {
        this.$message.success("ES全量操作成功");
        this.list();
      })
    }
  },
  created() {
    this.list();
  }
}

</script>

<style scoped>
.el-input {
  width: 200px;
}
</style>
